<?php

namespace App\Containers\AppSection\File\UI\API\Controllers;

use App\Containers\AppSection\File\Actions\CreateFileAction;
use App\Containers\AppSection\File\Actions\DownloadFileAction;
use App\Containers\AppSection\File\Actions\GetFilesAction;
use App\Containers\AppSection\File\Actions\GetFileAction;
use App\Containers\AppSection\File\UI\API\Requests\CreateFileRequest;
use App\Containers\AppSection\File\UI\API\Requests\GetFileRequest;
use App\Containers\AppSection\File\UI\API\Requests\DownloadFileRequest;
use App\Containers\AppSection\File\UI\API\Requests\GetFilesRequest;
use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Ship\Parents\Controllers\ApiController;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;

class Controller extends ApiController
{
    public function createFile(CreateFileRequest $request): JsonResponse
    {
        $file = app(CreateFileAction::class)->run($request);
        return $this->created($this->transform($file, FileTransformer::class));
    }

    public function getFiles(GetFilesRequest $request): array
    {
        $files = app(GetFilesAction::class)->run($request);
        return $this->transform($files, FileTransformer::class);
    }

    public function getFile($id, GetFileRequest $request): array
    {
        $file = app(GetFileAction::class)->run($id, $request);
        return $this->transform($file, FileTransformer::class);
    }

    public function downloadFile(DownloadFileRequest $request): StreamedResponse
    {
        return app(DownloadFileAction::class)->run($request);
    }
}
